@file:Suppress("SpellCheckingInspection")

package han.cirno.corrupt.components.school.impl.mju

import han.cirno.corrupt.data.instances.UserScoreData.Score
import org.json.JSONArray
import org.json.JSONObject

object MjuScoreResolver {
    fun analyse(jsonString: String):List<Score>{
        val jsonObject = JSONObject(jsonString)
        val itemsArray = jsonObject["items"] as JSONArray
        val scoreList:MutableList<Score> =ArrayList()
        for (i in 0 until itemsArray.length()){
            val value= itemsArray[i] as JSONObject
            scoreList.add(Score(
                name = value["kcmc"].toString(),
                year =  value["xnmmc"].toString(),
                term = value["xqmmc"].toString(),
                place = value["kkbmmc"].toString(),
                code = value["kch_id"].toString(),
                property = value["kcxzmc"].toString(),
                belonging = if (value.has("kcgsmc"))value["kcgsmc"].toString() else "",
                credits = value["xf"].toString(),
                score = value["cj"].toString(),
                gp = value["jd"].toString(),
                reExamScore = "_Nullity_",
                isReBuild = "_Nullity_",
                note = "_Nullity_",
                reExamNote = "_Nullity_",
                optional = value["kcxzmc"].toString().contains("选修")
            ))
        }
        return scoreList
    }
}